package pikes.ecma;

public class NewExpression extends PrintableExpression implements IMemberExpression {

	private ICallExpression expression = null;

	public NewExpression(ICallExpression expression) {
		super();
		this.expression = expression;
	}

	public NewExpression(CharSequence functionName) {
		this(new Identifier(functionName));
	}

	public NewExpression(Identifier functionName) {
		this(new FunctionCall(functionName));
	}

	public void visit(SyntaxTreeVisitor syntaxTreeVisitor) throws EcmaSyntaxVisitingException {
		syntaxTreeVisitor.New();
		syntaxTreeVisitor.whiteSpace();
		expression.visit(syntaxTreeVisitor);
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof NewExpression) {
			NewExpression rs = (NewExpression) obj;
			if (expression == null) {
				return rs.expression == null;
			}
			else {
				return expression.equals(rs.expression);
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		if (expression != null) {
			return expression.hashCode();
		}
		return getClass().hashCode();
	}

}
